-
Notifications
You must be signed in to change notification settings - Fork 4.2k
fix: Add automatic MIME type detection for file uploads #2520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add _guess_content_type_from_filename() for filename-based detection - Add _sniff_content_type_from_bytes() for content-based detection - Add _ensure_tuple_with_content_type() helper function - Enhance _transform_file() and _async_transform_file() to include content types - Support PDF, PNG, JPEG, GIF detection from file signatures - Fixes openai#2472: PDF upload via Files API now includes proper Content-Type This resolves the 400 Bad Request error when uploading PDF files for streaming use cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this and can no longer even upload a PDF
- Add _guess_content_type_from_filename() for filename-based detection - Add _sniff_content_type_from_bytes() for content-based detection - Add _ensure_tuple_with_content_type() helper function - Enhance _transform_file() and _async_transform_file() to include content types - Support PDF, PNG, JPEG, GIF detection from file signatures - Fixes openai#2472: PDF upload via Files API now includes proper Content-Type This resolves the 400 Bad Request error when uploading PDF files for streaming use cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working for me! I wasn't able to figure out how to pass the original message from the client to the API, but the upload now correctly adds the MIME type. Nicely done!
Maybe some tests would be in order too to ensure this behavior.
This resolves the 400 Bad Request error when uploading PDF files for streaming use cases.
example :

Before :
After :

Additional context & links